﻿using System.Collections.Specialized;

namespace Cosoware.Web.Navigation
{
    public partial class CalendarSiteMapProvider
    {
        /// <summary>
        /// Name of the provider.
        /// </summary>
        private string _name;

        /// <summary>
        /// Base base Url used as root key
        /// </summary>
        private string _urlBase;

        /// <summary>
        /// Base Url used as key
        /// </summary>
        private string _urlPattern;

        /// <summary>
        /// Root node title
        /// </summary>
        private string _title;

        /// <summary>
        /// Documents category
        /// </summary>
        private string _category;

        /// <summary>
        /// Initializes the <see cref="T:System.Web.SiteMapProvider"/> implementation, including any resources that are needed to load site map data from persistent storage.
        /// </summary>
        /// <param name="name">The <see cref="P:System.Configuration.Provider.ProviderBase.Name"/> of the provider to initialize.</param>
        /// <param name="attributes">A <see cref="T:System.Collections.Specialized.NameValueCollection"/> that can contain additional attributes to help initialize the provider. These attributes are read from the site map provider configuration in the Web.config file.</param>
        public override void Initialize(string name, NameValueCollection attributes)
        {
            lock (this)
            {
                base.Initialize(name, attributes);
                InitializeName(name);
                InitializeAttributes(attributes);
                CreateSiteMap();
            }
        }

        /// <summary>
        /// Initializes the name.
        /// </summary>
        /// <param name="name">The name.</param>
        private void InitializeName(string name)
        {
            _name = name;
        }

        /// <summary>
        /// Initializes the attributes.
        /// </summary>
        private void InitializeAttributes(NameValueCollection attributes)
        {
            _title = attributes["title"];
            _category = attributes["category"];
            _urlPattern = ApplicationPath + "/" + attributes["urlPattern"];
            _urlBase = ApplicationPath + "/" + attributes["urlBase"];
        }
    }
}
